package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.MediaLabelMapper;
import com.weixing.mall.provider.model.domain.MediaLabel;
import com.weixing.mall.provider.model.dto.ads.MediaLableDto;
import com.weixing.mall.provider.model.query.MediaLableQuery;
import com.weixing.mall.provider.model.vo.ads.MediaLableFormVo;
import com.weixing.mall.provider.model.vo.ads.MediaLableVo;
import com.weixing.mall.provider.service.IMediaLabelService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 媒体标签 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-18
 */
@Service
public class MediaLabelServiceImpl extends ServiceImpl<MediaLabelMapper, MediaLabel> implements IMediaLabelService {

    @Override
    public IPage<MediaLableVo> selectOfPage(Page initMpPage, MediaLableQuery mediaLableQuery) {
        return baseMapper.selectListOfPage(initMpPage,mediaLableQuery);
    }

    @Override
    public List<MediaLableVo> getList(MediaLableQuery mediaLableQuery) {
        return baseMapper.selectListOfPage(mediaLableQuery);
    }

    @Override
    public void save(MediaLableDto mediaLableDto) {
        MediaLabel mediaLabel = new MediaLabel();
        BeanUtils.copyProperties(mediaLableDto,mediaLabel);
        mediaLabel.setIsEnable(mediaLableDto.getIsEnable().getValue());
        if(null==mediaLableDto.getId()){
            save(mediaLabel);
        }else{
            mediaLabel.setUpdatedTime(new Date());
            updateById(mediaLabel);
        }
    }

    @Override
    public List<MediaLableFormVo> selectMediaLablList() {
        return baseMapper.selectMediaLablList();
    }
}
